﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using GeckoPhotos.Models;
using GeckoPhotos.Service;
using GeckoPhotos.Tests.TestUtil;
using GeckoPhotos.Repository;
using GeckoPhotos.Tests.Support;

namespace GeckoPhotos.Tests.NotReallyTests
{

    /// <summary>
    /// The tests presented in this class are not really tests, but small snippets of code 
    /// to allow me to run without implementing as part of the main product.
    /// </summary>
    [TestClass]
    public class DatabaseRunners
    {

        ///// <summary>
        ///// Hackily test adding an image to EFImageRepository.
        ///// </summary>
        //[TestMethod]
        //public void AddImageToEFRepository()
        //{
        //    DatabaseEntities dc = new DatabaseEntities("metadata=res://*;provider=System.Data.SqlClient;provider connection string='Data Source=.\\SQLEXPRESS;AttachDbFilename=\"C:\\Documents and Settings\\joel\\my documents\\visual studio 2010\\Projects\\GeckoPhotos\\GeckoPhotos\\App_Data\\Database.mdf\";Integrated Security=True;User Instance=True'");
        //    ImageServiceLayer s = new ImageServiceLayer(new EFImageRepository(dc), new EFUserRepository(dc));
        //    s.Insert(TestSettings.Standard, "", ImageUtil.StandardImageObject.Blob.Bytes, "joel");
        //}

        ///// <summary>
        ///// Resizes all images and thumbnails in the database to fit within the contraints defined in the created settings object.
        ///// Also recreates the images in the format specified in the settings.  Recreates thumbnails from the main image.
        ///// </summary>
        //[TestMethod]
        //public void ResizeAllImagesAndThumbnails()
        //{
        //    const string databasePath = @"D:\SVN\GeckoPhotos\trunk\GeckoPhotos\App_Data\Database.mdf";

        //    using (DatabaseEntities dc = new DatabaseEntities("metadata=res://*;provider=System.Data.SqlClient;provider connection string='Data Source=.\\SQLEXPRESS;AttachDbFilename=\"" + databasePath + "\";Integrated Security=True;User Instance=True'"))
        //    {
        //        var images = (
        //            from i in dc.Images.Include("Blob").Include("ThumbnailBlob")
        //            select i
        //            );
        //        foreach (var i in images)
        //        {
        //            var newImage = GeckoPhotos.Util.ImageUtil.CreateResizedImageToFitWidthHeight(
        //                GeckoPhotos.StaticSettings.Instance.MaxImageWidth,
        //                GeckoPhotos.StaticSettings.Instance.MaxImageHeight,
        //                i.Blob.Bytes,
        //                GeckoPhotos.StaticSettings.Instance.StandardImageFormat
        //                );
        //            var newThumbnailImage = GeckoPhotos.Util.ImageUtil.CreateResizedImageToFitWidthHeight(
        //                GeckoPhotos.StaticSettings.Instance.ThumbnailWidth,
        //                GeckoPhotos.StaticSettings.Instance.ThumbnailHeight,
        //                i.Blob.Bytes,
        //                GeckoPhotos.StaticSettings.Instance.StandardImageFormat
        //                );

        //            i.Blob.Bytes = newImage;
        //            i.Blob.MimeType = GeckoPhotos.Util.ImageUtil.GetMimeType(GeckoPhotos.StaticSettings.Instance.StandardImageFormat);

        //            i.ThumbnailBlob.Bytes = newThumbnailImage;
        //            i.ThumbnailBlob.MimeType = GeckoPhotos.Util.ImageUtil.GetMimeType(GeckoPhotos.StaticSettings.Instance.StandardImageFormat);
        //        }

        //        dc.SaveChanges();
        //    }
        //}

    }

}
